import Vue from 'vue'
import App from './App.vue'
//import VueCookies from 'vue-cookies'
import VueCookie from 'vue-cookie'
import router from './router/index'
//import pdfJs from 'pdfjs-dist'
import elementUI, {Message} from "element-ui";
import 'element-ui/lib/theme-chalk/index.css'     //引入element-ui的样式



Vue.use(VueCookie)
Vue.use(elementUI)
// Vue.use(pdfJs)
//Vue.prototype.$cookie = cookie;
Vue.config.productionTip = false


router.beforeEach((to, from, next) => {

  const token =  Vue.cookie.get("client_token")
  //console.log("beforeEach ===>>>",token)
  //debugger
     if(token) { // 判断是否已经登录过
         next()
     }
     else {
         if(to.path ==='/home/loginJob') { //如果有此资源且是登录页
             next()
         }
         else if(to.path ==='/home/loginCompany'){ //如果有此资源且是登录页
             next()
         }
         else if (to.path === '/home/registerJob'){
           next()
         }
         else if (to.path === '/home/registerCompany'){
           next()
         }
         else if (to.path!=='/home') { // 有此资源，没有登陆过，也不是登录页

             Message({
                type:'warning',
                message:'请先登录'
             })
            next({path: '/home'})
         }else if (to.path === '/home'){
           next()
         }
     }
})


let vm = new Vue({
  router:router,
  render: h => h(App),
}).$mount('#app')

console.log("this vm ==",vm)


